import React, { Component } from 'react';
import { Form, Button, DatePicker, Select } from 'antd';
import moment from 'moment';
import { connect } from 'dva';
@Form.create()
@connect(({ buyoutes }) => ({ buyoutes }))
export default class Exportcontent extends Component {
    handleSubmit = (e) => {
        e.preventDefault();
        this.props.form.validateFields((err, values) => {
            if (!err) {
                const { dispatch } = this.props;
                dispatch({
                    type: 'buyoutes/exportData',
                    payload: {
                        createTime: !!values.orderTime[0] ? [`${moment(values.orderTime[0]).format('YYYY-MM-DD')}`, `${moment(values.orderTime[1]).format('YYYY-MM-DD')}`] : [],//下单
                        status: !!values.orderState ? [`${values.orderState}`] : [],
                        time: !!values.createTime[0] ? [`${moment(values.createTime[0]).format('YYYY-MM-DD')}`, `${moment(values.createTime[1]).format('YYYY-MM-DD')}`] : [],//起租
                        type: 0
                    },
                    callback: (res) => {
                        this.props.handleCancel();
                        window.location.href = `${res.data}`;
                    }
                });
            }
        })
    }
    componentDidMount() {
        this.props.form.setFieldsValue({
            orderTime: [],
            createTime: [],
            orderState: ''
        })
    }
    render() {
        const { getFieldDecorator } = this.props.form;
        const { RangePicker } = DatePicker;
        const { Option } = Select;
        return (
            <Form layout='inline' onSubmit={this.handleSubmit}>
                <Form.Item label='下单时间'>
                    {
                        getFieldDecorator('orderTime')(
                            <RangePicker
                                style={{ width: 250 }}
                                placeholder={['下单开始时间', '下单结束时间']}
                            />)
                    }
                </Form.Item>
                <br />
                <Form.Item label='起租日期'>
                    {
                        getFieldDecorator('createTime')(
                            <RangePicker
                                style={{ width: 250 }}
                                placeholder={['创建开始时间', '创建结束时间']}
                            />)
                    }
                </Form.Item>
                <br />
                <Form.Item label='订单状态'>
                    {
                        getFieldDecorator('orderState')(
                            <Select placeholder='请选择订单状态' style={{ width: 250 }}>
                                <Option value="">全部</Option>
                                <Option value="WAIT_PAY">待支付</Option>
                                <Option value="FINISH">订单完成</Option>
                            </Select>
                        )
                    }
                </Form.Item>
                <div style={{ marginTop: '20px', paddingLeft: '80px' }}>
                    <Button type='primary' htmlType='submit'>确定导出</Button>
                </div>
            </Form>
        )
    }
}